import json
import logging

from fastapi import APIRouter

from app.api.endpoints.gps_api import query_gps
from app.models.z_bus_model import ZBusModel
from app.services.kkgc_csv_service import kkgc_csv_service
from app.services.kkgc_service import kkgc_service

from app.services.theme_service import theme_service
from app.utils.response_result import resp_500, resp_200

router = APIRouter()


# 新增配置
@router.post("/bus")
def interface_info(zBusModel: ZBusModel):
    try:
        logging.info(f"接收参数:{zBusModel.to_dict()}")
        type: str = zBusModel.type
        if type == "1":  # 主题查询
            return resp_200(data=theme_service.query_theme_withjson(zBusModel.body))
        elif type == "2":  # 疲劳驾驶
            return query_gps(zBusModel.body)
        elif type == "3":  # 卡口过车实时查询
            return resp_200(data=kkgc_service.search_kkgc_csv_list_result(zBusModel.body),message="过车实时查询成功")
        elif type == "4":  # 刷新csv
            return resp_200(data=kkgc_csv_service.refresh_csv(),message="刷新成功")
        else:
            return resp_500(message="暂不支持此接口")
    except Exception as e:
        logging.error(f"接口异常:{str(e)}")
        return resp_500(message=f"接口异常:{str(e)}")
